package contest1620;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class I {
    static Scanner cin = new Scanner(new BufferedInputStream(System.in));//大量输入优化版本
    static PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));//大量输出优化版本
    static PrintWriter cerr = new PrintWriter(System.err, true);//开启调试模式,一般输出量不大，不需要buffered

    public static void main(String[] args) {
        int T = cin.nextInt();
        while (T-- > 0) {
            for (char c : cin.next().toCharArray()) {
                if (Character.isLowerCase(c)) {
                    cout.print(Character.toUpperCase(c));
                } else {
                    cout.print(Character.toLowerCase(c));
                }
            }
            cout.println();
        }
        cin.close();
    }
}